package top.honlnk.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import top.honlnk.pojo.entity.OcrAdminInfo;
import top.honlnk.pojo.entity.SchoolTimetable;

import java.util.List;

@Mapper
public interface UserMapper {
    // 插入school_timetable表中的数据
    @Insert("INSERT INTO school_timetable(name, `table`, submit_id, key_id) VALUES (#{name}, #{table}, #{submitId}, #{keyId})")
    void insertByUpload(SchoolTimetable schoolTimetable);
    // 更新keyId和name同时存在的table
    @Update("UPDATE school_timetable SET `table` = #{table}, submit_id = #{submitId} WHERE key_id = #{keyId} AND `name` = #{name}")
    void updateByUpload(SchoolTimetable schoolTimetable);
    // 更新submitId对应的table
    @Update("UPDATE school_timetable SET `table` = #{table} WHERE submit_id = #{submitId}")
    void updateTableBySubmitId(String submitId, String table);
    // 获取submitId对应的school_timetable表中的数据
    @Select("SELECT * FROM school_timetable WHERE submit_id = #{submitId}")
    SchoolTimetable getSchoolTimetableBySubmitId(String submitId);
    // 验证submitId是否存在
    @Select("SELECT EXISTS(SELECT 1 FROM school_timetable WHERE submit_id = #{id})")
    boolean validate(String id);
    // 修改access_token
    @Update("UPDATE ocr_admin_info SET access_token = #{accessToken} WHERE ocr_name = #{ocrName}")
    void setAccessToken(String accessToken, String ocrName);
    // 获取ocr识别相关的配置信息
    @Select("select * from ocr_admin_info where ocr_name = #{ocrName}")
    OcrAdminInfo getOcrAdminInfo(String ocrName);
    // 验证keyId和name是否同时存在
    @Select("SELECT EXISTS(SELECT 1 FROM school_timetable WHERE key_id = #{keyId} AND name = #{name})")
    boolean getUnique(SchoolTimetable schoolTimetable);
    // 列表根据SubmitId获取全部信息。
    List<SchoolTimetable> getTableBySubmitId(List<String> submitIds);
}
